Show the code
summary(cars)Subtitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut elit odio. Donec fermentum tellus neque, vitae fringilla orci pretium vitae. Fusce maximus finibus facilisis. Donec ut ullamcorper turpis.
In this template many of the Quarto options for HTML output are listed in the YAML header. If you want to know more about these settings I recommend the HTML format reference for a complete list of available options.
Quarto offers also extensive YAML intelligence (completion and diagnostics) in the RStudio IDE and in VS Code for project files, YAML front matter, and executable cell options. Just start with some letters and press the tab key on the keyboard. You will see a small dialog box with a list of available options.
Code blocks in Quarto documents are treated in similar way as in Markdown documents. One important difference is that code chunk options (in Quarto also called ‘cell level options’) are typically included in special comments using #| at the top of code chunks rather than within the line that begins the chunk:
summary(cars)Please note that individual words are separated with a hyphen, not a dot, followed by a colon, not an equal sign as in R Markdown documents. Quarto uses this approach to both better accommodate longer options like fig-cap, fig-subcap, and fig-alt as well as to make it straightforward to edit chunk options within more structured editors that don’t have an easy way to edit chunk metadata (e.g. most traditional notebook UIs).
However, if you prefer it is still possible to include chunk options on the first line (e.g. ```{r, echo = FALSE}) as in R Markdown documents.
Quarto provides five different types of callouts that are an excellent way to draw extra attention to certain concepts.
The color and icon will be different depending upon the type that you select. You can choose between: note, warning, important, tip, and caution.
This is an example of a callout with a caption.
This is an example of a ‘folded’ caution callout that can be expanded by the user. You can use collapse="true" to collapse it by default or collapse="false" to make a collapsible callout that is expanded by default.
External images and R figures can be referenced with @fig-label, where ‘label’ is the name of the code chunk. These label names should not contain underscores to separate words, use hyphens here instead. Note that figures need to have a caption to be numbered and for cross-referencing, The caption is also set in the chunk option with #| fig-cap: "Your caption".
Tables require similarly a label and table caption for cross-referencing. But here, the cross-reference contains the prefix ‘tbl’: @tbl-label.
Cross-references to individual sections can simply be made with the prefix ‘sec’ and by adding a ‘{#sec-identifier}’ to any heading.
This is for example a cross-reference to Table 2 in Section 3.2 and a cross-reference to Fig. 6 in Section 3.3.
To create a reference-able code block, add a #lst-identifier along with a lst-cap attribute inside the curly braces (see code chunk example Listing 1). Note that the indication of the programming language requires for this static code block a dot set before the ‘r’.
Listing 1: Example for a referenceable code block
4+4A little math formula :
\[x = \sum_{i=1}^{n} \sqrt{\frac{y}{i}} \]
Here is a more complex example where the equation is embedded in a LaTeX equation environment including numbering and crossreferencing:
If the random variable \(Y\) follows a standard normal distribution, i.e. \(Y \sim N(0,1)\), it’s density function can be described with
\[ f_{Y}(y)=\varphi(y) \stackrel{\mathrm{def}}{=} \frac{1}{\sqrt{2 \pi}} \exp \left\{ -\frac{y^2}{2} \right\}, \quad y \in \mathbb{R}. \tag{1}\]
\(\pi\) represents the circle number or Ludolph’s number. The function
\[ F_{Y}(y)=\Phi(y) \stackrel{\mathrm{def}}{=} \int_{-\infty}^y \varphi(x) \,\mathrm{d}x, \quad y \in \mathbb{R} \tag{2}\]
represents then the distribution function of Equation 1.
Quarto includes several features aimed at making it easier to work with figures and subfigures, as well as for laying out panels that contain multiple figures, tables, or other content.
For instance, if you have several figures that appear as a group, you can create a figure div to enclose them (see Fig. 1 and Fig. 2).
The layout attribute enables the creation of much more complex layouts. Fig. 3 provides an example with a common figure caption and one identifier for all three.
R output is typically shown in the monospace font (here an example with the mtcars dataset in the subfolder data/):
mpg cyl disp hp
Min. :10.40 Min. :4.000 Min. : 71.1 Min. : 52.0
1st Qu.:15.43 1st Qu.:4.000 1st Qu.:120.8 1st Qu.: 96.5
Median :19.20 Median :6.000 Median :196.3 Median :123.0
Mean :20.09 Mean :6.188 Mean :230.7 Mean :146.7
3rd Qu.:22.80 3rd Qu.:8.000 3rd Qu.:326.0 3rd Qu.:180.0
Max. :33.90 Max. :8.000 Max. :472.0 Max. :335.0
Here is a simple table based on Markdown Syntax (Table 1).
| A | New | Table |
|---|---|---|
| left-aligned | center-aligned | right-aligned |
| $123 | $456 | $789 |
| italics | boldface |
Here is a sample table output using the knitr::kable() function.
tab <- aggregate(. ~ Species, data = iris, mean)
kable(tab)| Species | Sepal.Length | Sepal.Width | Petal.Length | Petal.Width |
|---|---|---|---|---|
| setosa | 5.006 | 3.428 | 1.462 | 0.246 |
| versicolor | 5.936 | 2.770 | 4.260 | 1.326 |
| virginica | 6.588 | 2.974 | 5.552 | 2.026 |
A base graphics histogram (Fig. 4).
Here for comparison a boxplot with a different image height (Fig. 5).
boxplot(mpg ~ am, mtcars)You can create a tabset via a markdown div with the class name panel-tabset. Each top-level heading within the div creates a new tab as shown below:
If the package ‘plotly’ is installed, the following code block will be executed:
p <- plotly::plot_ly(data = mtcars, x = ~mpg, y = ~wt, color = ~cyl)
plotly::add_markers(p)Quarto has native support for embedding Mermaid and Graphviz diagrams. This enables you to create flowcharts, sequence diagrams, state diagrams, gnatt charts, and more using a plain text syntax inspired by markdown.
Mermaid is a Javascript based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams (see Fig. 9).
flowchart LR
A[Hard edge] --> B(Round edge)
B --> C{Decision}
C --> D[Result one]
C --> E[Result two]
style C fill:#f9f,stroke:#333,stroke-width:4px
style E fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
Cell level options are here indicated with %%| instead of #|!
sequenceDiagram
participant Alice
participant Bob
Alice->>John: Hello John, how are you?
loop Healthcheck
John->>John: Fight against hypochondria
end
Note right of John: Rational thoughts
prevail!
John-->>Alice: Great!
John->>Bob: How about you?
Bob-->>John: Jolly good!
Useful links:
The Graphviz layout programs take descriptions of graphs in a simple text language and make diagrams in useful formats. Graphviz has many useful features for concrete diagrams, such as options for colors, fonts, tabular node layouts, line styles, hyperlinks, and custom shapes (see Fig. 10).
Cell level options are here indicated with //|!
Link a .bib document via the YAML header, and the bibliography will be printed at the end. The default bibliography style is provided in the sage-harvard.csl file (do not delete), which adopts the SAGE Harvard reference style.
References can be cited directly within the document using the Quarto equivalent of the citation system [@key], where key is the citation key in the first line of the entry in the .csl file. Example: (Taylor and Green, 1937). To cite multiple entries, separate the keys by semicolons (e.g., (Kamm, 2000; Knupp, 1999). You can also write in-text citations, as follows: Taylor and Green (1937) say this and that.
There is also the package citr which I highly recommend: citr provides functions and an RStudio add-in to search a BibTeX-file to create and insert formatted Markdown citations into the current document. If you are using the reference manager Zotero the add-in can access your reference database directly.
If you want to include a paragraph on the software used, here is some example text/code to get the current R and package versions. The code to generate a bibliography file including all package references has been already added at the beginning of this script (code chunk ‘generate-package-refs’).
All analyses were performed using the statistical software R (version 4.1.2) (R Core Team, 2021). This report, including tables and figures, was generated using the R packages ‘rmarkdown’ (version 2.14) (Allaire et al., 2022) and ‘knitr’ (version 1.39) (Xie, 2022).
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut elit odio. Donec fermentum tellus neque, vitae fringilla orci pretium vitae. Fusce maximus finibus facilisis. Donec ut ullamcorper turpis.
@online{name2022,
author = {Author name},
title = {Document Title},
date = {2022-01-04},
url = {https://example.com/summarizing-output},
langid = {en}
}